﻿using System.ComponentModel.DataAnnotations;
using System.Text.RegularExpressions;

namespace TrackSystem.Entities.Extensions
{
    public class SerialParamsAttribute : ValidationAttribute
    {
        //private const string Pattern = @"^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$";
        private const string Pattern = @"[E|O|N|]-[8|7]-[0|1|N]";

        public SerialParamsAttribute() : base("{0} 串口参数格式错误")
        {
            
        }

        public override bool IsValid(object? value)
        {
            if (value == null) return false;
            var s1 = value as string;
            return Regex.IsMatch(s1, Pattern);
        }
    }
}
